package com.gitee.zhanyao.monomer.util;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanyao
 */
public class JacksonUtil {

    /**
     * 将 json 转换为 list 对象
     *
     * @param json  字符串
     * @param clazz 对象
     * @return list
     * @throws IOException
     */
    public static <T> List<T> getList(String json, Class<T> clazz) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, clazz);
        return objectMapper.readValue(json, javaType);
    }

}
